package com.tb.boxman;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;

/**
 * Created by 汪贵春 on 2016/7/10.
 */
public class GameView extends View{

    public static final int GAME_MENU = 0;
    public static final int GAME_HELP = 1;
    public static final int GAMING    = 2;
    public static final int GAME_WIN  = 3;
    public static int gameState = GAME_MENU;

    public static int screenW,screenH;

    private GameMenu gameMenu;
    private Gaming gaming;
    private GameWin gameWin;


    public static GameView main = null;

    public GameView(Context context, AttributeSet attrs) {
        super(context, attrs);
        main = this;

        setFocusable(true);
        setFocusableInTouchMode(true);

        gameMenu = new GameMenu();
        gaming = new Gaming();
        gameWin = new GameWin();

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        Paint paint = new Paint();
        screenH = this.getHeight();
        screenW = this.getWidth();

        switch (gameState){
            case GAME_MENU:
                gameMenu.draw(canvas,paint);
                break;
            case GAME_HELP:
                break;
            case GAMING:
                gaming.draw(canvas,paint);
                break;
            case GAME_WIN:
                gameWin.draw(canvas,paint);
                break;
        }



    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {


        switch (gameState){
            case GAME_MENU:
                gameMenu.onTouchEvent(event);
                break;
            case GAME_HELP:
                break;
            case GAMING:
                gaming.onTouchEvent(event);
                break;
            case GAME_WIN:

                break;
        }



        invalidate();
        return true;
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK){
            switch (gameState){
                case GAME_MENU:
                    gameMenu.onBackKeyUp();
                    break;
                case GAME_HELP:

                    break;
                case GAMING:
                    gaming.onBackKeyUp();
                    break;
                case GAME_WIN:
                    gameWin.onBackKeyUp();

                    break;
            }
        }
        return true;
    }



}
